package com.winai.launcher.view.timeManager;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.winai.launcher.R;
import com.winai.launcher.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AlarmTagActivity extends BaseActivity {

    @BindView(R.id.str_title)
    TextView strTitle;
    @BindView(R.id.et_tag)
    EditText etTag;

    private Context mContext = this;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_alarm_tag);
        ButterKnife.bind(this);
        start();
    }

    private void start() {
        initObject();
    }

    private void initObject() {
        strTitle.setText("编辑闹钟");
        String tag = getIntent().getStringExtra("tag");
        if (!TextUtils.isEmpty(tag)) {
            etTag.setText(tag);
        }
        // 光标的位置
        int index = etTag.getText().toString().length();
        etTag.setSelection(index);
    }

    @OnClick({R.id.iv_back, R.id.iv_home, R.id.iv_empty})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.iv_back:
                Intent intent = new Intent();
                intent.putExtra("tag", etTag.getText().toString());
                setResult(Activity.RESULT_OK, intent);
                finish();
                break;
            case R.id.iv_home:
                //模拟HOME
                Intent it = new Intent(Intent.ACTION_MAIN);
                it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                it.addCategory(Intent.CATEGORY_HOME);
                mContext.startActivity(it);
                break;
            case R.id.iv_empty:
                etTag.setText("");
                break;
        }
    }
}
